package com.seed.web.struts.sysmanager;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.seed.commons.dbquery.PageViewForSQL;
import com.seed.service.sysmanager.IMenuModel;
import com.seed.web.core.BaseActionSupport;
import com.seed.web.form.sysmanager.MenuModelForm;

@Controller
@Scope("prototype")
public class MenuModelAction extends BaseActionSupport {

	private static final long serialVersionUID = 1L;

	private MenuModelForm menumodel;

	@Resource
	private IMenuModel menumodelService ;

	public MenuModelForm getMenumodel() {
		return menumodel;
	}

	public void setMenumodel(MenuModelForm menumodel) {
		this.menumodel = menumodel;
	}

	@Resource(name = "pageViewForSQL")
	private PageViewForSQL pv;

	public PageViewForSQL getPv() {
		return pv;
	}

	public void setPv(PageViewForSQL pv) {
		this.pv = pv;
	}

	public String updateMenumodel() throws Exception {
		
		return "" ;
	}
	
	public String findMenuModelAll() throws Exception {

		this.getBaseform().getRequest().setAttribute("menumodel", this.menumodelService.queryMenuModel());

		if ("addmenuitem".equals(this.getBaseform().getType())) {
			return "addmenuitem";
		} if ("privilegemodel".equals(this.getBaseform().getType())) {
			
			this.getBaseform().getRequest().setAttribute("roleId", this.getBaseform().getParam()) ;
			return "privilegemodel";
		} else {
			return "findmenumodelall";
		}
	}
	
	public String saveMenumodel() throws Exception {
		boolean flag = this.menumodelService.saveMenuModel(menumodel);
		if (flag) {
			saveMessage("菜单模块添加成功！");
		} else {
			saveMessage("菜单模块添加 失败！");
		}
		return "msg";
	}

	public String findMenumodel() throws Exception {
		pv.setPageModel(this.menumodelService.getScrollData(pv.getFirstResult(),
				pv.getLineSize()));
		
		this.getBaseform().getRequest().setAttribute("scrolldata", pv);
		return "findmenumodel";
	}
}
